// order_pkg/pages/orderdetail/orderdetail.js
Page({
  data: {
    orderDetail: {}
  },
  onLoad(query) {
    this.getOrderDetail(query.orderId)
  },
  async getOrderDetail(orderId) {
    const res = await wx.http.get('/order/detail', {orderId})
    const orderDetail = res.data.data.order
    this.setData({orderDetail})
  },
  // 复制订单号
  copyOrderNo(ev) {
    const orderNo = ev.mark.orderNo
    wx.setClipboardData({
      data: orderNo,
      success: () => {
        wx.showToast({
          title: '复制成功',
          icon: 'none'
        })
      }
    })
  },
  // 取消订单
  async orderCancel(ev) {
    const orderId = ev.mark.orderId
    const res = await wx.http.post('/order/cancel', {orderId})
    if(res.data.status === 200) {
      wx.showToast({
        title: '取消成功'
      })
    }
  }
})